﻿using UnityEngine;
using System.Collections;

public class BattleResultWindow : MonoBehaviour {
    public UILabel[] characterNameLabel;
    public UILabel[] characterLevelLabel;
    public UILabel[] expLabel;

    [HideInInspector]
    public bool[] expDone = new bool[4] { false, false, false, false };

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void SetCharacterInfos()
    {
        int[][] memberExp = null;
        int i=0;
        foreach(int charId in UserData.Instance.userModel.choiceMembers)
        {
            characterNameLabel[i].text = TextController.GetStringWithId(string.Format("charName{0}", UserData.Instance.userModel.members_dic[charId.ToString()].name));
            characterLevelLabel[i].text = string.Format("Lv {0}", UserData.Instance.userModel.members_dic[charId.ToString()].level);
            if( WorldSceneManager.isSentSearch && !BattleManager.Instance.isBossBattle )
				memberExp = UserData.Instance.researchResultData.memberExp;
			else if( WorldExtensionBattleStageScene.isExpansionWar )
				memberExp = UserData.Instance.expansionWarResultData.memberExp;
			else if( BattleManager.Instance.isBossBattle )
				memberExp = UserData.Instance.raidBossResultData.memberExp;
			else if( UserData.Instance.isQuickPVPBattle )
				memberExp = UserData.Instance.quickPvPResultData.memberExp;

			SoundController.PlaySound("UI_score");
            if (memberExp != null)
            {
                for (int k = 0; k < memberExp.Length; k++)
                {
                    StartCoroutine(Co_SetExpValue(k, memberExp[k][1]));
                }
            }
            i++;
        }
    }

    IEnumerator Co_SetExpValue(int index, int endValue)
    {
        float f = 0f;
        float pValue = 0f;
        int curValue = 0;

        while (curValue < endValue)
        {
            curValue = (int)Mathf.Lerp(0, endValue, f);
            expLabel[index].text = string.Format("+{0}", curValue);
            f += Time.deltaTime / 2;
            yield return null;
        }

        yield return new WaitForSeconds(2f);

        expDone[index] = true;
    }
}
